package com.hh.demo.controller;

import com.hh.demo.doc.CourseDoc;
import com.hh.demo.dto.CourseSearchDto;
import com.hh.demo.result.JSONResult;
import com.hh.demo.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class CourseEsController {
    @Resource
    private ICourseEsService courseEsService;

    /**
     * 查询es里的课程，高级查询加分页
     * @param
     * @return
     */
    @PostMapping("/course/search")
    public JSONResult search(@RequestBody CourseSearchDto courseSearchDto){
        return JSONResult.success(courseEsService.search(courseSearchDto));
    }

    /**
     * 保存课程到Es
     * @param doc
     * @return
     */
    @PostMapping("/saveCourse")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        courseEsService.saveCourse(doc);
        return JSONResult.success();
    }

    /**
     * 删除Es中的课程
     * @param
     * @return
     */
    @PostMapping("/deleteCourse/{id}")
    public JSONResult deleteCourse(@PathVariable("id") Long id){
        courseEsService.deleteCourse(id);
        return JSONResult.success();
    }
}